if(CROSS_COMPILE)

set(CMAKE_SYSTEM_NAME Linux)

if(CROSS_COMPILE STREQUAL arm)
set(TOOLCHAIN_DIR "/home/tj/code/RK3308_git/alps/buildroot/output/rockchip_rk3308_mg_32/host")
set(TOOLCHAIN_PREFIX arm-rockchip-linux-gnueabihf)
else()
set(TOOLCHAIN_DIR "/home/tj/code/O13399_git/alps/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu")
set(TOOLCHAIN_PREFIX aarch64-linux-gnu)
endif()

set(CMAKE_SYSROOT "${TOOLSCHAIN_PATH}/sysroot")
#CMAKE_SYSROOT只有在3.0以上的版本才有效
#SET(CMAKE_SYSROOT "${TOOLSCHAIN_PATH}/sysroot")
set(SYSROOT_PATH "${TOOLSCHAIN_PATH}/sysroot")
#message(STATUS "Using sysroot path: ${SYSROOT_PATH}")

#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${SYSROOT_PATH}" CACHE INTERNAL "" FORCE)
#SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --sysroot=${SYSROOT_PATH}" CACHE INTERNAL "" FORCE)
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${SYSROOT_PATH}" CACHE INTERNAL "" FORCE)
#SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} --sysroot=${SYSROOT_PATH}" CACHE INTERNAL "" FORCE)

#告诉cmake是进行交叉编译
set(CMAKE_CROSSCOMPILING TRUE)

# Define name of the target system
set(CMAKE_SYSTEM_NAME "Linux")
# Define the compiler
set(CMAKE_C_COMPILER ${TOOLCHAIN_CC})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_CXX})

#库和同头文件查找的路径。
#set(CMAKE_FIND_ROOT_PATH "${SYSROOT_PATH}" "${CMAKE_PREFIX_PATH}" "${TOOLSCHAIN_PATH}")

# search for programs in the build host directories
#set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
#set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
#set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)



set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_C_COMPILER   ${TOOLCHAIN_DIR}/bin/${TOOLCHAIN_PREFIX}-gcc)
set(GNU_FLAGS "-mfpu=vfp -fPIC")
set(CMAKE_CXX_FLAGS "${GNU_FLAGS} ")
set(CMAKE_C_FLAGS "${GNU_FLAGS}  ")

set(CMAKE_FIND_ROOT_PATH  ${TOOLCHAIN_DIR}
 	${TOOLCHAIN_DIR}/TOOLCHAIN_PREFIX/include
 	${TOOLCHAIN_DIR}/TOOLCHAIN_PREFIX/lib
 	${SYSROOT_PATH}/lib)


#link_directories(${SYSROOT_PATH}/lib)
endif()